package fmi.chesstern.ui.gui;

import java.awt.Image;
import java.awt.Toolkit;
import java.util.HashMap;
import java.util.Map;

import fmi.chesstern.pieces.ChessPiece;
import fmi.chesstern.pieces.ChessPieceColor;
import fmi.chesstern.pieces.ChessPieceType;

public class ChessPieceResourceLocator {
	private static final Map<ChessPiece, Image> chessPieceToImage;
	
	private static void addImage(ChessPiece piece, String imageLocation) {
		chessPieceToImage.put(piece, Toolkit.getDefaultToolkit().getImage(imageLocation));
	}
	
	static {
		chessPieceToImage = new HashMap<ChessPiece, Image>();
		
		addImage(ChessPiece.getPiece(ChessPieceType.BISHOP, ChessPieceColor.WHITE), "res/white_bishop.png");
		addImage(ChessPiece.getPiece(ChessPieceType.KING, ChessPieceColor.WHITE), "res/white_king.png");
		addImage(ChessPiece.getPiece(ChessPieceType.KNIGHT, ChessPieceColor.WHITE), "res/white_knight.png");
		addImage(ChessPiece.getPiece(ChessPieceType.PAWN, ChessPieceColor.WHITE), "res/white_pawn.png");
		addImage(ChessPiece.getPiece(ChessPieceType.QUEEN, ChessPieceColor.WHITE), "res/white_queen.png");
		addImage(ChessPiece.getPiece(ChessPieceType.ROOK, ChessPieceColor.WHITE), "res/white_rook.png");
		addImage(ChessPiece.getPiece(ChessPieceType.BISHOP, ChessPieceColor.BLACK), "res/black_bishop.png");
		addImage(ChessPiece.getPiece(ChessPieceType.KING, ChessPieceColor.BLACK), "res/black_king.png");
		addImage(ChessPiece.getPiece(ChessPieceType.KNIGHT, ChessPieceColor.BLACK), "res/black_knight.png");
		addImage(ChessPiece.getPiece(ChessPieceType.PAWN, ChessPieceColor.BLACK), "res/black_pawn.png");
		addImage(ChessPiece.getPiece(ChessPieceType.QUEEN, ChessPieceColor.BLACK), "res/black_queen.png");
		addImage(ChessPiece.getPiece(ChessPieceType.ROOK, ChessPieceColor.BLACK), "res/black_rook.png");	
	}
	
	public static Image getImageOf(ChessPiece piece) {
		return chessPieceToImage.get(piece);
	}
}
